﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NCKH.Personal
{
    public partial class Hopdongdetai : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                hiendetai();
        }
        private void hiendetai()
        {
            string sqlSelect = "SELECT MaDT,TenDT FROM DETAI ";
            string connectionString = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection Cnn = new SqlConnection(connectionString))
            {
                using (SqlCommand Cmd = new SqlCommand(sqlSelect, Cnn))
                {
                    Cnn.Open();
                    using (SqlDataReader Rd = Cmd.ExecuteReader())
                    {
                        ddrtendt.Items.Insert(0, "-- Chọn tên đề tài --");
                        while (Rd.Read())
                        {
                            ddrtendt.Items.Add(
                                new ListItem(Rd["TenDT"].ToString(),
                                    Rd["MaDT"].ToString()));
                        }
                    }
                    Cnn.Close();
                }
            }
        }
        protected void nhomthuchien_Insert()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("tennhom_INSERT", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Tennhom", txtbengiao.Text);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                }
            }
        }
        protected void thongtinnnc_Insert()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("thongtinnnc_INSERT", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@MaNNC", txtmadd.Text);
                    cmd.Parameters.AddWithValue("@TenNNC", txtdaidien.Text);
                    cmd.Parameters.AddWithValue("@Diachi", txtdcbg.Text);
                    cmd.Parameters.AddWithValue("@Chucvu", txtcv.Text);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                }
            }
        }
        protected void thongtincqcq_Insert()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("coquancq_INSERT", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@TenCQCQ", txtbennhan.Text);
                    cmd.Parameters.AddWithValue("@Diachi", txtdcbn.Text);
                    cmd.Parameters.AddWithValue("@SDT", txtdtbn.Text);
                    cmd.Parameters.AddWithValue("@Fax", txtfax.Text);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                }
            }
        }
        protected void hddt_Insert()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("hddt_INSERT", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Dieukhoan", CKEditor1.Text);
                    cmd.Parameters.AddWithValue("@Ngayki", txtngaykihd.Text);
                    cmd.Parameters.AddWithValue("@Ngaycohieuluc", txtngaycohieuluc.Text);
                   
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                }
            }
        }
        protected void btnluu_Click(object sender, EventArgs e)
        {
            nhomthuchien_Insert();
            thongtincqcq_Insert();
            thongtinnnc_Insert();
            hddt_Insert();
            thongbao("Thành công");
        }
        private void thongbao(string Noidung)
        {

            ScriptManager.RegisterStartupScript(this, this.GetType(), "UpdateCom", "alert('" + Noidung + "');return false;", true);
        }
        protected void btnin_Click(object sender, EventArgs e)
        {
        }

        protected void btnhuy_Click(object sender, EventArgs e)
        {
            txtbengiao.Text = txtbennhan.Text = txtcv.Text = txtdaidien.Text = txtdcbg.Text = txtdcbn.Text = txtdtbn.Text = txtfax.Text = txtngaycohieuluc.Text = txtngaykihd.Text = CKEditor1.Text = string.Empty;
        }
    }
}